

#ifndef _DATATRANSMISSIONDDS_H_
#define _DATATRANSMISSIONDDS_H_

using namespace std;

#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
//publisher
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>

//subscriber
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>




class PubListener final : public eprosima::fastdds::dds::DataWriterListener
{
public:

    PubListener() = default;

    ~PubListener() override = default;

    void on_publication_matched(
            eprosima::fastdds::dds::DataWriter* writer,
            const eprosima::fastdds::dds::PublicationMatchedStatus& info) override;

    int matched = 0;
};

class SubListener final : public eprosima::fastdds::dds::DataReaderListener
{
public:

    SubListener() = default;

    ~SubListener() override = default;

    void on_data_available(
            eprosima::fastdds::dds::DataReader* reader) override;

    void on_subscription_matched(
            eprosima::fastdds::dds::DataReader* reader,
            const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override;

    int matched = 0;
    uint32_t samples = 0;
};

#define INIT_PUB    1
#define INIT_SUB    2
class DataTransmissionDds
{
public:
    eprosima::fastdds::dds::DomainParticipant* participant_;
    eprosima::fastdds::dds::Topic* topic_;
    eprosima::fastdds::dds::TypeSupport type_;

    eprosima::fastdds::dds::Publisher* publisher_;
    eprosima::fastdds::dds::DataWriter* writer_;

    eprosima::fastdds::dds::Subscriber* subscriber_extern;
    eprosima::fastdds::dds::Subscriber* subscriber_intern;
    eprosima::fastdds::dds::DataReader* reader_;    
public:

    DataTransmissionDds() = default;

    virtual ~DataTransmissionDds();

    virtual bool init(int type = INIT_PUB);

    virtual void run();

    virtual void setDdsAttribute(const std::string &topicName, const std::string &participantName, const uint32_t domainId);

    

};


#endif